package cn.ffcs.security.service;

import java.util.Date;

import cn.ffcs.base.service.BaseService;
import cn.ffcs.security.dao.IRoleDAO;
import cn.ffcs.security.model.Role;
import cn.ffcs.security.model.User;
import cn.ffcs.util.context.ApplicationContextUtil;

/**
 * 
 * 角色服务层接口实现<br/> <table>
 * <tr>
 * <td>负责人/principal: </td>
 * <td colspan="2">liuzhh</td>
 * <tr>
 * <td>修改记录/revision:</td>
 * <td colspan="2"></td>
 * </tr>
 * <tr>
 * <td>日期:</td>
 * <td>修改人:</td>
 * <td>修改说明:</td>
 * </tr>
 * <tr>
 * <td></td>
 * <td></td>
 * <td></td>
 * </tr>
 * </table>
 * @author liuzhh
 * @version $Id$
 */
public class RoleService<R extends Role> extends BaseService<R> implements
        IRoleService<R>
{
    //角色DAO
    private IRoleDAO roleDAO;
    
    /**
     * 新增或修改操作
     * @param baseEntity
     */
    public void saveOrUpdate(R role)
    {
        if (role != null)
        {
            if (role.getId() == null || role.getId() == 0)
            {   
                //设置操作人
                User currUser=ApplicationContextUtil.getUserContextObject().getCurrUser();
                if (currUser!=null)
                    role.setCreator(currUser.getUserID());
                //设置有效时间
                role.setBegin(roleDAO.getCurrSysdate());
                Long l=Long.valueOf("9783941568000");
                Date end=new Date(l);
                role.setEnd(end);
                //保存数据
                roleDAO.save(role);
            }
            else
            {
                roleDAO.update(role);
            }
        }
    }
    /**
     * @return the roleDAO
     */
    public IRoleDAO getRoleDAO()
    {
        return roleDAO;
    }
    /**
     * @param roleDAO the roleDAO to set
     */
    public void setRoleDAO(IRoleDAO roleDAO)
    {
        this.roleDAO = roleDAO;
    }
}
